<?php
/** [文档表数据层视图模型]
 * @Author: 976123967@qq.com
 * @Date:   2015-01-16 16:29:41
 * @Last Modified by:   happy
 * @Last Modified time: 2015-03-14 17:41:26
 */
class ArticleViewModel extends ViewModel{
	public $tableName = 'article';

	public $viewFields  = array(
		'article'=>array(
			'*',
			'_type'=>'INNER',
		),
		'user'=>array(
			'username','uid',
			'_type'=>'INNER',
			'_on' =>'user.uid=article.user_uid',
		),
		'category'=>array(
			'cid','cname','remark',
			'_type'=>'INNER',
			'_on' =>'category.cid=article.category_cid',
		)
	); 


	/**
	 * [find_one_by_aid 读取一条信息]
	 * @return [type] [description]
	 */
	public function find_one_by_aid($data)
	{
		// 关联表
		$this->viewFields[$data['table']] = array(
			'*',
			'_type'=>'INNER',
			'_on'=>$data['table'].'.article_aid=article.aid'

		);
		return  $this->where(array('aid'=>$data['aid']))->find();

	}

	/**
	 * [get_field_by_aid 查找单条记录中一个字段的数据，通过主键]
	 * @param  [type] $fid 	 [description]
	 * @param  [type] $field [description]
	 * @return [type]        [description]
	 */
	public function get_field_by_aid($data)
	{
		// 关联表
		$this->viewFields[$data['table']] = array(
			'*',
			'_type'=>'INNER',
			'_on'=>$data['table'].'.article_aid=article.aid'

		);
		return $this->where(array('aid'=>$data['aid']))->getField($data['field']);
	}


	
	


	/**
	 * [find_list 读取数据更具where]
	 * @param  [type] $where [description]
	 * @param  [type] $order [description]
	 * @param  [type] $limit [description]
	 * @param  [type] $field [description]
     * @param  [type] $table [description]
	 * @return [type]        [description]
	 */
	public function find_list($where,$order,$limit,$field,$table)
	{

		// 关联表
		$this->viewFields[$table] = array(
			'*',
			'_type'=>'INNER',
			'_on'=>$table.'.article_aid=article.aid'

		);
		return $this->where($where)->field($field)->order($order)->limit($limit)->select();
	}

}